<template>
	<view class="content">
		<view class="content-box">

			<view class="item-box" v-for="(item,i) in viewData" :key="i" @click="gotoMessage(item.conversation_id)">

				<view class="img-box">
					<image v-if="item.duiyou_list[0].tou_xiang == ''" class="img" src="../../static/minilogo.png" mode=""></image>
					<image v-if="item.duiyou_list[0].tou_xiang != ''" class="img" :src="base64Img(item.duiyou_list[0].tou_xiang)" mode=""></image>
				</view>
				<view class="left-name">
					<view class="team-title">
						{{item.team_name}}
					</view>
					<view class="new-messge">
						<view class="new-user">
							{{item.latest_news.latest_news_name + ':'}}
						</view>
						<view class="new-content">
							{{item.latest_news.latest_news}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue'

	import {
		getMessageList
	} from '@/api/message_api.js'

	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'

	import {
		base64Img
	} from '@/tools/tools.js'


	const userData = reactive({
		openid: ''
	})

	const viewData = ref([])

	const _getMessageList = (id) => {
		getMessageList(id).then((res) => {
			console.log(res.result);
			viewData.value = res.result
		})
	}

	// 跳转消息
	const gotoMessage = (id) => {
		uni.navigateTo({
			url: `/pages/message_mode/message_content_view?id=${false}&telid=${id}&check=${1}`
		})
	}


	onShow(() => {
		console.log('数据更新了');
		uni.getStorage({
			key: 'openid',
			success: function(res) {
				userData.openid = res.data.openid
				console.log(res.data.openid)
				_getMessageList(res.data.openid)
			}
		})
	})
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background-color: #f5f5f6;

		.content-box {
			padding: 20rpx 20rpx 0 20rpx;

			.item-box {
				display: flex;
				margin-top: 20rpx;
				background-color: white;

				.img-box {
					margin-right: 20rpx;

					.img {
						width: 140rpx;
						height: 140rpx;
						border-radius: 8rpx;
					}
				}

				.left-name {
					padding-top: 4rpx;

					.team-title {
						font-size: 30rpx;
						color: #000000;
						font-weight: 800;
					}

					.new-messge {

						display: flex;
						font-weight: 200;
						margin-top: 20rpx;
						font-size: 24rpx;

						.new-user {
							margin-right: 20rpx;
						}
					}
				}
			}
		}
	}
</style>